<?php
class sis_setup_grup_dokumen_model extends MY_Model {
	var $model = 'sis_setup_grup_dokumen';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	dok.id_dokumen, dok.nama_dokumen ";
			$arr_data = $this->GetAllJenisAnggota();
			for($i=0, $max_i=count($arr_data); $i<$max_i; $i++){
				$row = $arr_data[$i];
				$key	= strtolower($row['kd_jenis_anggota']);
				$ls_sql	.=	",(CASE WHEN EXISTS(SELECT 1 FROM sis_setup_grup_dokumen_detail x WHERE x.kd_grup_dokumen = '".post('kd_grup_dokumen')."' AND x.id_dokumen = dok.id_dokumen AND LOWER(x.kd_jenis_anggota)='".$key."') THEN 'Y' ELSE 'N' END) visible_".$key." ".
							",(SELECT x.st_mandatory FROM sis_setup_grup_dokumen_detail x WHERE x.kd_grup_dokumen = '".post('kd_grup_dokumen')."' AND x.id_dokumen = dok.id_dokumen AND LOWER(x.kd_jenis_anggota)='".$key."' AND NVL(x.st_mandatory,'N') = 'Y') mandatory_".$key." ";
			}
        $ls_sql	.= "FROM	sis_setup_dokumen dok
                    WHERE    (UPPER(dok.id_dokumen) LIKE '%".strtoupper(post('keyword'))."%' 
                            OR UPPER(dok.nama_dokumen) LIKE '%".strtoupper(post('keyword'))."%' ) 
                    ORDER BY nama_dokumen";
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetAllJenisAnggota(){
		$result	= $this->db->query("SELECT kd_jenis_anggota, nama_jenis_anggota FROM sis_setup_jenis_anggota ORDER BY kd_jenis_anggota");
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
	
	function GetAllGrupDokumen(){
		$result	= $this->db->query("SELECT kd_grup_dokumen value, nama_grup_dokumen display FROM sis_setup_grup_dokumen ORDER BY kd_grup_dokumen");
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
}
?>